<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app"></div>
    <script>
      const url1 =
        "https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png";
      const url2 =
        "https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png";

      function loadImg(src) {
        return new Promise((resolve, reject) => {
          const img = document.createElement("img");
          img.onload = () => {
            resolve(img);
          };
          img.onerror = () => {
            reject(new Error(`图片加载失败 ${src}`));
          };
          img.src = src;
        });
      }

      const appEle = document.querySelector("#app");

      loadImg(url1)
        .then((img1) => {
          console.log(img1.width);
          return img1;
        })
        .then((img1) => {
          console.log(img1.height);
          appEle.appendChild(img1);
          return loadImg(url2);
        })
        .then((img2) => {
          appEle.appendChild(img2);
        })
        .catch((err) => {
          console.error(err);
        });
    </script>
  </body>
</html>
